<template>
  <div class="student-id">
    <div class="login-title">
      <img src="@/assets/login/logo@2x.png" alt="" />
    </div>
    <div class="content">
      <span class="choose-title">请选择注册角色</span>
      <span class="recommended-title">为你推荐精彩内容</span>
      <div class="choose-sport">
        <div
          class="sport"
          v-for="(item, index) in sportList"
          :key="index"
        >
          <div class="sport-rows" :style="`background-image:url(${item.remark})`">
            <img :src="item.checked ? require('@/assets/login/sported.png') : require('@/assets/login/sport.png')" alt="" @click="selectHandle(index)"/>
          </div>
          <span>{{ item.name }}</span>
        </div>
      </div>
      <div class="sure-btn" @click="sureBtn">完成</div>
    </div>
  </div>
</template>
<script>
import { getSport } from "../../api/otwoo.js";
export default {
  data() {
    return {
      sportList: [],
      params: {
        name: "",
        page: {
          notConvert: true,
          order: "",
          pageNumber: 0,
          pageSize: 0,
          sort: "",
        },
        typeIds: [1000],
      },
    };
  },
  mounted() {
    getSport(this.params).then((res) => {
      let sportList = res.result.records.splice(0,3);
      this.sportList = sportList.map((item) =>{
        item.checked = false;
        return item;
      });
    });
  },
  methods:{
    selectHandle(index){
        this.sportList[index].checked = !this.sportList[index].checked;
    },
    sureBtn(){
        let idStr = [];
        this.sportList.forEach((item) => {
            if(item.checked){
                idStr.push(item.id);
            }
        })
        if(idStr === ''){
            this.$Message.error('请选择运动目的')
        }else{
            this.$emit('sportHandle',idStr.join(','));
        }
    }
  }
};
</script>
<style lang="scss" scoped>
.student-id {
  width: 100%;
  height: 100vh;
  overflow: hidden;
  background: url("../../assets/login/beij@2x.png") no-repeat;
  background-size: cover;
  .login-title {
    background-color: none;
    margin-top: calc(37 / 1920 * 100vw);
    margin-left: calc(77 / 1920 * 100vw);
    > img {
      width: calc(390 / 1920 * 100vw);
      height: calc(40 / 1920 * 100vw);
    }
  }
  .content {
    margin: calc(100 / 1920 * 100vw) auto 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    .choose-title {
      font-size: calc(36 / 1920 * 100vw);
      font-weight: bold;
      color: #fff;
    }
    .recommended-title {
      font-size: calc(24 / 1920 * 100vw);
      color: #fff;
      margin-top: calc(30 / 1920 * 100vw);
    }
    .choose-sport {
      width: calc(850 / 1920 * 100vw);
      margin-top: calc(82 / 1920 * 100vw);
      display: flex;
      justify-content: space-between;

      .sport {
        display: flex;
        flex-direction: column;
        align-items: center;
        .sport-rows {
          width: calc(190 / 1920 * 100vw);
          height: calc(190 / 1920 * 100vw);
          border-radius: calc(95 / 1920 * 100vw);
          background-size: cover;
          position: relative;
          > img {
            width: calc(46 / 1920 * 100vw);
            height: calc(46 / 1920 * 100vw);
            cursor: pointer;
            position: absolute;
            bottom: 0;
            right: 0;
          }
        }
        > span {
          font-size: calc(30 / 1920 * 100vw);
          color: #fff;
          margin-top: calc(20 / 1920 * 100vw);
        }
      }
    }
    .sure-btn{
        width: calc(200/1920*100vw);
        height: calc(50/1920*100vw);
        background: #EA3F47;
        color: #fff;
        text-align: center;
        line-height: calc(50/1920*100vw);
        cursor: pointer;
        font-size: calc(20/1920*100vw);
        border-radius: calc(25/1920*100vw);
        margin-top: calc(50/1920*100vw);
    }
  }
}
</style>